{
  "name": "Case 15 – Real Estate Buyer Qualification",
  "nodes": [
    {
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2,
      "position": [0, 0],
      "parameters": {
        "formTitle": "Real Estate Buyer Qualification",
        "formDescription": "Upload buyer income and financial documents for eligibility assessment",
        "formFields": {
          "values": [
            { "fieldLabel": "Buyer Name", "requiredField": true },
            { "fieldLabel": "Email id", "fieldType": "email", "requiredField": true },
            {
              "fieldLabel": "Income_Documents",
              "fieldType": "file",
              "acceptFileTypes": ".pdf",
              "requiredField": true
            }
          ]
        }
      }
    },
    {
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [220, 0],
      "parameters": {
        "inputDataFieldName": "Income_Documents",
        "name": "={{ $json['Buyer Name'] + '_Income_Documents' }}",
        "folderId": "REPLACE_WITH_BUYER_DOCS_FOLDER_ID"
      }
    },
    {
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [420, 0],
      "parameters": {
        "operation": "download",
        "fileId": "={{ $json.id }}"
      }
    },
    {
      "name": "Extract Income Documents",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [620, 0],
      "parameters": {
        "operation": "pdf"
      }
    },
    {
      "name": "Download Lending & Risk Rules",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [820, 0],
      "parameters": {
        "operation": "download",
        "fileId": "REPLACE_WITH_LENDING_RULES_FILE_ID"
      }
    },
    {
      "name": "Extract Lending Rules",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [1020, 0],
      "parameters": {
        "operation": "pdf"
      }
    },
    {
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [220, 260],
      "parameters": {
        "promptType": "define",
        "text": "=Buyer Income & Financial Documents:\n{{ $('Extract Income Documents').item.json.text }}\n\nLending & Risk Assessment Rules:\n{{ $('Extract Lending Rules').item.json.text }}",
        "options": {
          "systemMessage": "You are a Senior Credit & Risk Underwriting Manager for a real estate platform.\n\nYOUR OBJECTIVE:\nDetermine whether a buyer is financially eligible to bid on a property, based on income stability, affordability ratios, leverage limits, and credit risk guidelines.\n\nANALYSIS FRAMEWORK (MANDATORY):\n1. INCOME STABILITY – employment type, income continuity, and reliability of sources.\n2. AFFORDABILITY – EMI-to-income ratio, living expense coverage, and buffer availability.\n3. LEVERAGE & LIABILITIES – existing loans, debt obligations, and leverage thresholds.\n4. CREDIT RISK INDICATORS – repayment behavior, defaults, and financial discipline signals.\n5. STRESS RESILIENCE – ability to absorb interest rate or income shocks.\n\nYOU MUST PRODUCE ONE JSON OBJECT WITH EXACTLY THESE FIELDS. ALL FIELDS ARE MANDATORY.\n\nJSON SCHEMA (STRICT):\n{\n  \"Buyer_Name\": \"string\",\n  \"Employment_Type\": \"Salaried | Self-Employed\",\n  \"Annual_Gross_Income_INR_Lacs\": \"number\",\n  \"Existing_Liabilities_INR_Lacs\": \"number\",\n  \"Proposed_Property_Value_INR_Cr\": \"number\",\n  \"Estimated_EMI_INR_Lacs_per_Year\": \"number\",\n  \"EMI_to_Income_Ratio_Percentage\": \"number\",\n  \"Affordability_Assessment\": \"Weak | Moderate | Strong\",\n  \"Credit_Risk_Level\": \"Low | Medium | High\",\n  \"Overall_Eligibility_Score_out_of_100\": \"number\",\n  \"Buyer_Qualification_Decision\": \"Eligible to Bid | Not Eligible\",\n  \"Risk_Notes\": \"string\"\n}\n\nINSTRUCTIONS:\n- Numeric fields MUST contain numbers only.\n- Do NOT add, remove, or rename fields.\n- Output ONLY valid JSON.\n- IMMEDIATELY call the Google Sheets Append Row tool using this JSON."
        }
      }
    },
    {
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [0, 420],
      "parameters": {
        "model": {
          "mode": "list",
          "value": "gpt-4.1-mini"
        }
      }
    },
    {
      "name": "Append row",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [420, 460],
      "parameters": {
        "operation": "append",
        "documentId": "REPLACE_WITH_GOOGLE_SHEET_ID",
        "sheetName": "Real Estate Buyer Qualification Register"
      }
    },
    {
      "name": "Send Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [420, 260],
      "parameters": {
        "sendTo": "={{ $('On form submission').item.json['Email id'] }}",
        "subject": "Real Estate Buyer Qualification – Status Update",
        "message": "={{ 'Dear ' + $('On form submission').item.json['Buyer Name'] + ',<br><br>Your financial eligibility has been reviewed based on our lending and risk assessment criteria. We will inform you of your bidding eligibility shortly.<br><br>Real Estate Risk Team' }}"
      }
    }
  ],
  "connections": {
    "On form submission": { "main": [[{ "node": "Upload file" }]] },
    "Upload file": { "main": [[{ "node": "Download file" }]] },
    "Download file": { "main": [[{ "node": "Extract Income Documents" }]] },
    "Extract Income Documents": { "main": [[{ "node": "Download Lending & Risk Rules" }]] },
    "Download Lending & Risk Rules": { "main": [[{ "node": "Extract Lending Rules" }]] },
    "Extract Lending Rules": { "main": [[{ "node": "AI Agent" }]] },
    "OpenAI Chat Model": { "ai_languageModel": [[{ "node": "AI Agent" }]] },
    "Append row": { "ai_tool": [[{ "node": "AI Agent" }]] },
    "AI Agent": { "main": [[{ "node": "Send Email" }]] }
  },
  "active": false
}
